package com.ddtech.business.check.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ddtech.business.common.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * <p>
 * 考核表
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value = "Check对象", description = "考核表")
@TableName("check_info")
public class Check extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "考核名称")
    private String checkName;

    @ApiModelProperty(value = "考核描述")
    private String checkDesc;

    @ApiModelProperty(value = "封面图")
    private String coverImg;

    @ApiModelProperty(value = "开始时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    @ApiModelProperty(value = "结束时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "答题时限（分钟）")
    private Integer limeTime;

    @ApiModelProperty(value = "多选题目数量")
    private Integer multipleNum;

    @ApiModelProperty(value = "单选题目数量")
    private Integer singleNum;

    @ApiModelProperty(value = "判断题目数量")
    private Integer judgeNum;

    @ApiModelProperty(value = "是否随机")
    private Integer isRandom;

    @ApiModelProperty(value = "考试类型")
    private Integer checkType;

    @ApiModelProperty(value = "合格分值")
    private Double standardScore;

    @ApiModelProperty(value = "排序号")
    private Integer sort;


    @ApiModelProperty(value = "是否可以考试:-1未开始 1 进行中 2:过期")
    @TableField(exist = false)
    private Integer isStart;

    public Integer getIsStart() {
        LocalDateTime now = LocalDateTime.now();
        if (startTime.isAfter(now)) {
            return -1;
        }
        if (endTime.isBefore(now)) {
            return 2;
        }
        if (startTime.isBefore(now) && endTime.isAfter(now)) {
            return 1;
        }
        return 0;
    }
}